package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: ComponentList
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
**
** Abstract: The ComponentList class provides a data structure (Vector) to store
** the system components.  The following methods are provided:
**
**	void AddComponent( Communication Obj ) - Adds a new Component to the list. All the
**    issues of casting are taken care of within this class.
**
**	Student Obj = GetNextComonent() - Returns the component pointed at the current
**	position pointed to by the internal list pointer of the internal list. Subsequent
**	calls will return the next component object in the list.  A null object is returned
**	if list is empty or the end of list has been reached.
**
**	public Communication GetComponent( String ComponentName ) - Given the name of the
**	object (at instantiation), this method will return the associated component object
**	to the caller of this method.
**
**	public Integer GetComponent( String ComponentName ) - Given the name of the
**	object (at instantiation), this method will return the associated component
**	object's Integer ID to the caller of this method.
**
***************************************************************************************
** Modification Log
**************************************************************************************
**
**************************************************************************************/

class ComponentList extends List
{
	ComponentList()
	{
		super();

	} // Constructor

	public void AddComponent( Communication Component )
	{
		AppendItemToList( (Object) Component );

	} // AddStudent

	public Object GetNextComponent()
	{
		return (Object) GetItemFromList();

	} // GetNextStudent

	public Communication GetComponent( String ComponentName )
	{
		Communication CurrentComponent = null;
		boolean Done = false;
		boolean Result = false;

		GoToFrontOfList();

		while (!Done )
		{
		   CurrentComponent = (Communication) GetNextComponent();

		   if ( CurrentComponent == null )
		   {
				Done = true;

		   } else {
				if ( ComponentName.compareTo( CurrentComponent.ComponentName ) == 0 )
				{
			 	   Result = true;
				   Done = true;

				} // if
		   } // if

	 	} // while

		return( (Communication) CurrentComponent );

	} // GetComponent

	public Integer GetComponentID( String ComponentName )
	{
		Communication CurrentComponent = null;
		boolean Done = false;
		boolean Result = false;

		GoToFrontOfList();

		while (!Done )
		{
		   CurrentComponent = (Communication) GetNextComponent();

		   if ( CurrentComponent == null )
		   {
				Done = true;

		   } else {

			 	if ( ComponentName.compareTo( CurrentComponent.ComponentName ) == 0 )
				{
			 	   Result = true;
				   Done = true;

				} // if
		   } // if
	 	} // while

		if ( Result == true )
		   return( (Integer) CurrentComponent.RegistrationNumber );
		else
		   return( null );

	} // GetComponentID

} //ComponentList